﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using transportsystem.DTO;
using UTIL;
using System.Data;

using System.Data.SqlClient;



namespace transportsystem.DAO
{
    public class TuyenDAO
    {
        public static DataTable layDanhSachTuyenTheoMa(int matuyen)
        {
            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_TraCuuTuyenTheoMa";
            SqlParameter[] sp = new SqlParameter[1];
            sp[0] = new SqlParameter("@matuyen",matuyen);
            DataSet ds = SqlDataAccessHelper.LoadDataWithParameter(procName,sp);
            if (ds != null)
                return ds.Tables[0];
            return null;
        }
        public static DataTable layDanhSachTuyen()
        {
            SqlDataAccessHelper.ConnectSQLServer();            
            string procName = "sp_TraCuuTuyen '','','','','','','','',''";
            DataSet ds = SqlDataAccessHelper.LoadData(procName);
            if (ds != null)
                return ds.Tables[0];
            return null;
        }

        public static bool capNhatTuyen(Tuyen tuyen)
        {
            SqlCommand cmd = SqlDataAccessHelper.CreateCommand("sp_ThemTuyen");
            cmd.Parameters.Add("@matuyen", SqlDbType.Int).Value = tuyen.Matuyen;
            cmd.Parameters.Add("@tentuyen", SqlDbType.NVarChar).Value = tuyen.Tentuyen;
            cmd.Parameters.Add("@noidi", SqlDbType.NVarChar).Value = tuyen.Noidi;
            cmd.Parameters.Add("@noiden", SqlDbType.NVarChar).Value = tuyen.Noiden;
            cmd.Parameters.Add("@dodai", SqlDbType.Int).Value = tuyen.Dodai;
            cmd.Parameters.Add("@trangthai", SqlDbType.Int).Value = tuyen.Trangthai;
            cmd.Parameters.Add("@hesogiave", SqlDbType.Float).Value = tuyen.Hesogiave;
            cmd.Parameters.Add("@malichtrinh", SqlDbType.Int).Value = tuyen.Malichtrinh;
            cmd.Parameters.Add("@mota", SqlDbType.NVarChar).Value = tuyen.Mota;

            return SqlDataAccessHelper.ExecCmd(cmd);
        }

        public static bool xoaTuyen(Tuyen tuyen)
        {
            SqlCommand cmd = SqlDataAccessHelper.CreateCommand("sp_XoaTuyen");
            cmd.Parameters.Add("@matuyen", SqlDbType.Int).Value = tuyen.Matuyen;
            return SqlDataAccessHelper.ExecCmd(cmd);
        }
        public static DataTable traCuuTuyen(string tentuyen)
        {
            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_TraCuuTuyen '','" +tentuyen + "','','','','','','',''";
            DataSet ds = SqlDataAccessHelper.LoadData(procName);
            if (ds != null)
                return ds.Tables[0];
            return null;
        }
        public static bool capNhatHeSoGiaVe(Tuyen tuyen)
        {
            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_CapNhatHeSoGiaVe";
            SqlParameter[] sp = new SqlParameter[2];
            sp[0] = new SqlParameter("@matuyen", tuyen.Matuyen);
            sp[1] = new SqlParameter("@heso", tuyen.Hesogiave);
            DataSet ds = SqlDataAccessHelper.LoadDataWithParameter(procName, sp);
            if (ds != null)
                return true;
            return false;
        }
    }


    
}
